package mill;

import java.util.*;
import java.io.Serializable;

public class MillPark extends Observable implements Serializable {

	private int m_parkID;
	private String m_location;
	
	private List<IMill> m_mills;

	public MillPark(int parkid, String location) {
		super();
		m_parkID = parkid;
		m_location = location;
		
		m_mills = new ArrayList<IMill>();
	}
	
	public synchronized int get_parkID() {
		return m_parkID;
	}
	
	public synchronized int get_size() {
		return m_mills.size();
	}

	public synchronized String get_location() {
		return m_location;
	}

	public List<IMill> getMills(){
		return m_mills;
	}
	
	public boolean addMill(IMill mill)
	{
		try
		{
			m_mills.add(mill);
			return true;
		}
		catch(Exception ex)
		{
			return false;
		}
	}

	public boolean removeMill(IMill mill)
	{
		try {
			m_mills.remove(mill);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public IMill findMill(int serialNumber)
	{
		IMill mill;
		
		for (Iterator it = m_mills.iterator(); it.hasNext(); ) {

			mill = (IMill)it.next();
			
			if(mill.getSerialNumber() == serialNumber)
				return mill;
		}
		
		return null;
	
	}
	
	public void notifyUpdate()
	{
		setChanged();
	    notifyObservers(this);

	}
	
	@Override
	public String toString()
	{
		return m_parkID + " " + m_location;
	
	}
	
}
